package com.grm.datasource.controller;

import com.grm.datasource.common.Result;
import com.grm.datasource.entity.User;
import com.grm.datasource.mapper.UserMapper;
import com.grm.datasource.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/add")
    public Result add(@RequestBody User user){
        userService.add(user);
        return Result.success("success");
    }

    @PutMapping("/update")
    public Result update(@RequestBody User user){
        userService.update(user);
        return Result.success("success");
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        userService.delete(id);
        return Result.success("success");
    }

    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Long id){
        User user = userService.getById(id);
        return Result.success("success",user);
    }

    @GetMapping("/get/list")
    public Result getList(){
        List<User> users = userService.getList();
        return Result.success("success",users);
    }
}
